﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace StreetlightGames.XnaEngine
{
    public class TextRenderer
    {
        private string _fontName;
        private SpriteFont _font;
        private SpriteBatch _spriteBatch;

        public TextRenderer(string fontName)
        {
            _fontName = fontName;
        }

        public void LoadContent(ContentManager contentManager, SpriteBatch spriteBatch)
        {
            _font = contentManager.Load<SpriteFont>(_fontName);
            _spriteBatch = spriteBatch;
        }

        public void DrawString(string text, Vector2 position, Color color)
        {
            _spriteBatch.Begin();
            _spriteBatch.DrawString(_font, text, position, color);
            _spriteBatch.End();
        }

        public void DrawStringCentered(string text, Vector2 position, Color color)
        {
            Vector2 size = _font.MeasureString(text);
            DrawString(text, position - size * 0.5f, color);
        }
    }
}
